{include file="public/header" /}
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>添加/编辑</h5>
                </div>
                <div class="ibox-content">

					<form id="formEdit" method="post" class="form-horizontal" action="{:url('edit')}">

	
						<div class="form-group">
							<label class="col-sm-3 control-label"><span style="color:red;">*&nbsp;</span>名称</label>
							<div class="input-group col-sm-4">
								<input type="text" name="title" placeholder="请输入" autocomplete="off" class="form-control"
									   value="{:isset($list.title)?$list.title:''}" >
							</div>
						</div>
						<div class="form-group">
							<label class="col-sm-3 control-label"><span style="color:red;">*&nbsp;</span>学习人数</label>
							<div class="input-group col-sm-4">
								<input type="number" name="study_nums" placeholder="请输入" autocomplete="off" class="form-control" value="{:isset($list.study_nums)?$list.study_nums:''}" >
							</div>
						</div>
						<div class="form-group">
							<label class="col-sm-3 control-label"><span style="color:red;">*&nbsp;</span>价格(元)</label>
							<div class="input-group col-sm-4">
								<input type="text" name="price" placeholder="请输入" autocomplete="off" class="form-control" value="{:isset($list.price)?$list.price:''}" ><span style="color:red;">0元为免费课程</span>
							</div>
						</div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">年级：</label>
                            <div class="input-group col-sm-4">
                                <select class="form-control m-b chosen-select" name="grade_id" id="grade_id">
                                    <option value="">==请选择==</option>
                                    {if !empty($grade_list)}
                                        {foreach name="grade_list" item="vo"}
                                            <option value="{$vo.id}" {if condition="isset($list['grade_id']) and ($list['grade_id'] eq $vo['id'])"}selected{/if}>{$vo.title}</option>
                                        {/foreach}
                                    {/if}
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">科目：</label>
                            <div class="input-group col-sm-4">
                                <select class="form-control m-b chosen-select" name="subject_id" id="subject_id">
                                    <option value="">==请选择==</option>
                                    {if !empty($subject_list)}
                                        {foreach name="subject_list" item="vo"}
                                            <option value="{$vo.id}" {if condition="isset($list['subject_id']) and ($list['subject_id'] eq $vo['id'])"}selected{/if}>{$vo.title}</option>
                                        {/foreach}
                                    {/if}
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">版本：</label>
                            <div class="input-group col-sm-4">
                                <select class="form-control m-b chosen-select" name="version_id" id="version_id">
                                    <option value="">==请选择==</option>
                                    {if !empty($version_list)}
                                        {foreach name="version_list" item="vo"}
                                            <option value="{$vo.id}" {if condition="isset($list['version_id']) and ($list['version_id'] eq $vo['id'])"}selected{/if}>{$vo.title}</option>
                                        {/foreach}
                                    {/if}
                                </select>
                            </div>
                        </div>
						<div class="form-group">
							<label class="col-sm-3 control-label"><span style="color:red;">&nbsp;</span>课程封面</label>
							<div class="input-group col-sm-4">
								<span>{notempty name="$list['photo']"}<img style="margin-left: 10px;height:80px;" src="{:isset($list.photo)?$list.photo:''}">{/notempty}</span>
								<input type="text" class="file_value form-control" value="{:isset($list.photo)?$list.photo:''}" name="photo" lay-verify="uploadimg">
								<button type="button" class="layui-btn layui-btn-primary upload_img upload_img1" lay-data="{id:1}"><i class="layui-icon">&#xe67c;</i> 上传</button>   
							</div>
						</div>
						
						
						<div class="form-group">
							<label class="col-sm-3 control-label"><span style="color:red;">&nbsp;</span>讲师名称</label>
							<div class="input-group col-sm-4">
								<input type="text" name="teacher" placeholder="请输入" autocomplete="off" class="form-control" value="{:isset($list.teacher)?$list.teacher:''}" >
							</div>
						</div>
						<div class="form-group">
							<label class="col-sm-3 control-label"><span style="color:red;">&nbsp;</span>讲师头像</label>
							<div class="input-group col-sm-4">
								<span>{notempty name="$list['teacher_head']"}<img style="margin-left: 10px;height:80px;" src="{:isset($list.teacher_head)?$list.teacher_head:''}">{/notempty}</span>
								<input type="text" class="file_value form-control" value="{:isset($list.teacher_head)?$list.teacher_head:''}" name="teacher_head" lay-verify="uploadimg">
								<button type="button" class="layui-btn layui-btn-primary upload_img upload_img2" lay-data="{id:2}"><i class="layui-icon">&#xe67c;</i> 上传</button>   
							</div>
						</div>
						<div class="form-group">
							<label class="col-sm-3 control-label"><span style="color:red;">&nbsp;</span>讲师介绍</label>
							<div class="input-group col-sm-6">
								<textarea name="teacher_desc" style="width:100%;height:300px;">{:isset($list.teacher_desc)?$list.teacher_desc:''}</textarea>
							</div>
						</div>

                        <div class="form-group">
                            <label class="col-sm-3 control-label " for="myEditor">课程介绍：</label>
                            <div class="input-group col-sm-9">
                                <script src="/static/admin/ueditor/ueditor.config.js" type="text/javascript"></script>
                                <script src="/static/admin/ueditor/ueditor.all.js" type="text/javascript"></script>
                                <textarea name="info" style="width:90%" id="myEditor">{$list.info??''}</textarea>
                                <script type="text/javascript">
                                    var editor = new UE.ui.Editor();
                                    editor.render("myEditor");
                                </script>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">是否首页推荐：</label>
                            <div class="col-sm-6">
                                <div class="radio i-checks">
                                    <input type="radio" name='is_home' value="1" {if condition="$list['is_home'] eq 1 "}checked{/if}/>是&nbsp;&nbsp;
                                    <input type="radio" name='is_home' value="0" {if condition="$list['is_home'] eq 0 "}checked{/if}/>否
                                </div>
                            </div>
                        </div>
						
						<div class="form-group">
							<label class="col-sm-3 control-label"><span style="color:red;"></span>排序</label>
							<div class="input-group col-sm-4">
								<input type="text" name="sort" placeholder="请输入"  value="{:isset($list.sort)?$list.sort:''}"  autocomplete="off" class="form-control">
							</div>
						</div>
						
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <div class="col-sm-4 col-sm-offset-3">
								<input type="hidden" name="id" value="{:isset($list['id'])?$list['id']:''}">
                                <button class="btn btn-primary" type="submit"><i class="fa fa-save"></i> 保存</button>&nbsp;&nbsp;&nbsp;
                                <a class="btn btn-danger" href="javascript:history.go(-1);"><i class="fa fa-close"></i> 返回</a>
                            </div>
                        </div>
					</form>

                </div>
            </div>

        </div>
    </div>
</div>
{include file="public/footer" /}
<script type="text/javascript" src="/static/admin/js/layui.js"></script>
<link rel="stylesheet" href="/static/admin/css/layui.css" media="all"/>
<script type="text/javascript">
layui.use(['upload'], function () {
	var upload = layui.upload;
	//单图上传
	upload.render({
		elem: '.upload_img',
		url: "{:url('Upload/upload_oss')}",
		accept:'images',
		acceptMime:'image/*',
		done: function(data){
			var id = this.id;
			var icon=5;
			if(!data.code){
				icon=6;
				//this.elem.prev().prev("span").html('<img style="margin-left: 10px;height:80px;" src="'+data.data.src+'">');
				//this.elem.prev(".file_value").val(data.data.src);
				$(".upload_img"+id).prev().prev("span").html('<img style="margin-left: 10px;height:80px;" src="'+data.data.src+'">');
				$(".upload_img"+id).prev(".file_value").val(data.data.src);
			}
			layer.msg(data.msg, {icon:icon,time: 1500});
		},
		error: function(){
			layer.msg('上传失败', {icon:icon,time: 1500});
		}
	});
});
</script>
<script type="text/javascript">
	
    //提交
    $(function(){
        $('#formEdit').ajaxForm({
            beforeSubmit: checkForm, 
            success: complete, 
            dataType: 'json'
        });
        
        function checkForm(){
            if( '' == $.trim($('input[name="title"]').val())){
                layer.msg('请输入名称',{icon:2,time:1500,shade: 0.1}, function(index){
                layer.close(index);
                });
                return false;
            }
            if( '' == $.trim($('input[name="price"]').val())){
                layer.msg('请输入价格',{icon:2,time:1500,shade: 0.1}, function(index){
                layer.close(index);
                });
                return false;
            }
        }


        function complete(data){
            if(data.code==1){
                layer.msg(data.msg, {icon: 6,time:1500,shade: 0.1}, function(index){
                    window.location.href="{:url('course/index')}";
                });
            }else{
                layer.msg(data.msg, {icon: 5,time:1500,shade: 0.1});
                return false;   
            }
        }
     
    });

</script>
</body>
</html>